
#ifndef _PROCESSROUTER_MESSAGE_H_
#define _PROCESSROUTER_MESSAGE_H_

#include <ev.h>
#include <list>
#include <string>
#ifndef Q_MOC_RUN 
#include <boost/lexical_cast.hpp> 
#endif
#include "iothread.h"
#include "rf/event/RFEventBase.h"
#include "message_struct.pb.h"

namespace ProcessRouter {

class Message {
    public:
        Message(std::string conent)
            : m_content(conent)
            , m_isNull(false)
        {
        }

        Message()
            : m_isNull(true)
        {
        }

        std::string content() { return m_content; }

        bool isNull() { return m_isNull; }

        void setContent(std::string content) { m_content = content; }

    protected:
        std::string m_content;
        bool m_isNull;
};

class MessageProtocol {
    public:
        virtual void didRecevied() {}
        virtual void didConnected() {}
        virtual void didError() {}
};

class Listener {
    public:

        Listener(IOThread *thread);
        ~Listener();

        void init(int fd);
        void setClient(MessageProtocol *client);
        MessageProtocol *client();
        ev_io* watcher();
        int fd();

        void remove();
        virtual int childPid() { return -1; }
        virtual int pid() { return -1; }

        void addEvent();
        void removeEvent();

        void onRecevied();
        void onConnected();
        void onError();

        void setPriority(int priority);
        int priority();

        IOThread *currentThread();
    private:
        ev_io m_watcher;
        int m_fd;
        MessageProtocol *m_client;
        IOThread *m_currentThread;
        int m_priority;
};

} // namespace end

#endif

